package com.dbs.donatebooksystem.controller;

import com.dbs.donatebooksystem.Service.RequirementService;
import com.dbs.donatebooksystem.pojo.Requirement;
import com.dbs.donatebooksystem.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin(origins = "http://localhost:8080",originPatterns = "http://localhost:8081")
public class RequirementVontroller {

    @Autowired
    private RequirementService requirementService;


    @GetMapping("/RequireAllSelect")
    public Result RequiresAllSelect(){
        log.info("查询需求");
        List<Requirement> requireList =requirementService.SelectRequirements();
        return Result.success(requireList);
    }

    @PostMapping("/InsertRequire")
    public  Result InsertRequire(@RequestBody Requirement requirement){
        log.info("增加需求,{}",requirement);
        boolean b=requirementService.InsertRequire(requirement);
        if(b){
            return Result.success("成功发布");
        }
        return Result.error("发布失败");
    }
}
